<template>
	<view>
		<view class="completePage" id="pdfDom">
			<h1>签收+ 电子回执</h1>
			<div>
				服务完成二维码
				<tki-qrcode ref="qrcode" :val="qrcode" :size="300" unit="upx" />
				出示此二维码给服务方确认
			</div>
			<view class="billId" v-if="Status!=3">
				<a @click="download">
					<view>
						<span>单号: {{ billid }}</span>
					</view>
					<view><span>下载</span></view>
				</a>
			</view>
			<view class="billId" v-else>
				<view>
					<span>此回执单已提交差异</span><br />
					<span>请等待发货方确认</span>
				</view>
			</view>
			<!-- <p>
				您也可以登录<a href="http://chzq.yoojet.com">http://chzq.yoojet.com</a>
				<br />
				使用网页批量下载数据
			</p>
			<p>您的账户即是您的手机号</p> -->
		</view>
	</view>
</template>

<script>
	import tkiQrcode from "@/components/tki-qrcode/tki-qrcode.vue"
	export default {
		components: {
			tkiQrcode
		},
		data() {
			return {
				billid: "",
				Status: '',
				id: '',
				qrcode: ''
			}
		},
	
		onLoad(options) {
			console.log(options);
			this.Status = options.Status
			this.billid = uni.getStorageSync('billId')
			this.id = uni.getStorageSync("Id");
			// wxa24101ce1f340e47
			this.qrcode =
				'https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxde354ac424a66adc&redirect_uri=https%3A%2F%2Fhzq.yoojet.com%2F%23%2FSendSMSPublic%3Fid%3D' +
				this.id + '&response_type=code&scope=snsapi_userinfo&state=123#wechat_redirect'
			console.log(this.qrcode);
			setTimeout(() => {
				this.$refs.qrcode._makeCode()
			}, 100)
		},
		// 返回监听
		onBackPress(e) { 
		
		},
		
		onUnload() {
			console.log('卸载页面了',)
			// 1. 获取当前页面栈实例（此时最后一个元素为当前页）
		  uni.setStorageSync('tabIndex',1)
			 // 返回收货 中的已收货页面
			 uni.navigateBack({
				 delta:2
			 })
		},
		

		methods: {
			download() {
				uni.showLoading()
				this.$http('get', '/BO/BillList/GetDownloadPDF?id=' + this.id).then(res => {
					if (res.Success) {
						this.downloadFile(res.Data)
					} else {
						uni.showToast({
							icon: 'none',
							title: res.Msg,
						})
					}
					uni.hideLoading()
				})
			},
			downloadFile(url) {
				uni.downloadFile({
					url: url,
					success: (data) => {
						console.log(data);
						if (data.statusCode === 200) {
							uni.saveFile({
								tempFilePath: data.tempFilePath, //临时路径
								success: function(res) {
									uni.showToast({
										icon: 'none',
										mask: true,
										title: '文件已保存：' + res.savedFilePath, //保存路径
										duration: 3000,
									});
									setTimeout(() => {
										//打开文档查看
										uni.openDocument({
											filePath: res.savedFilePath,
											showMenu: true,
											success: function(res) {
												// console.log('打开文档成功');
											}
										});
									}, 2000)
								}
							});
						}
					},
					complete: () => {
						uni.hideLoading()
					}
				});
			}
		}
	} 
</script>

<style scoped lang="scss">
	.completePage {
		line-height: 1.5;
		height: calc(100vh - 44px);
		background-image: $complete;
		background-repeat: no-repeat;
		background-size: cover;
		text-align: center;
		overflow: hidden;
		font-size: 18px;
		color: #000;

		h1 {
			padding: 6vh 0;
			margin: 0;
			color: #fff;
			font-size: 34px;
		}

		.billId {
			margin-top: 40rpx;
			font-size: 22px;

			view {
				span {
					border-bottom: 1px solid #d50700;
				}
			}
		}

		p {
			margin-top: 10vh;
		}
	}
</style>
